<?php ob_start(); ?>
<?php  
    //login.php  
      
	require_once 'model/global.inc.php';  
   
	$error = "";  
	$username = "";  
	$password = "";  
     
	//check to see if they've submitted the login form  
	if(isset($_POST['submit-login'])) {  
   
		$username = $_POST['username'];  
		$password = $_POST['password'];  
    
		$userTools = new UserTools();  
		if($userTools->login($username, $password)){  
			//successful login, redirect them to a page 
                    $user = unserialize($_SESSION['user']);
                    $memid = $user->memid;
                    echo $memid;
                    $ip=$_SERVER['REMOTE_ADDR'];
                    $last_date = date("Y-m-d H:i:s",time());
                    $sql = "update tblmember set last_ip = '$ip',last_joined_datetime = '$last_date' where memid = '$memid'";
                    mysql_query($sql) or die(mysql_error());  
					$isadmin = $user->isadmin;
      	 			if($isadmin == 1){header("Location: admin/index.php");}
      	 			else
						header("Location: ../../index.php");  
		}else{  
			$error = "Incorrect username or password. Please try again.";  
		}  
	}  
?>  

	<?php  
	if($error != "")  
	{  
		echo $error."<br/>";  
	}  
	?> 
    <center>
	    <div style="background:#e9a786; height:auto; width:300px">
	    
	    <form action="login.php" method="post"> 
	     <h1 style="color:#FFF"><label>Login</label></h1>
	
	       <font color="#FFFFFF;"> Username:</font> <input type="text" name="username" value="<?php echo $username; ?>" /><br/> <br> 
	        <font color="#FFFFFF;"> Password:</font> <input type="password" name="password" value="<?php echo $password; ?>" /><br/>  <br/>  
	        <input type="submit" value="Login" name="submit-login" />  <p></p>
	    </form>  
	    </div>
    </center>
 